// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Utils.java

package ys8583.parse;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Utils
{

	public static final byte BLANK = 32;
	public static final byte ZERO = 48;
	public static final byte BLANK_ = 32;
	public static final byte ZERO_ = 48;

	public Utils()
	{
	}

	public static String byteToString(byte bytes[])
	{
		return new String(bytes);
	}

	public static String byteToString(byte bytes[], String charsetName)
	{
		try
	    {
	      return new String(bytes, charsetName); } catch (UnsupportedEncodingException e) {
	    }
	    return byteToString(bytes);
	}

	public static byte[] stringToByte(String src, String charsetName)
	{
		if (isEmpty(src)) return null;
	    try
	    {
	      return src.getBytes(charsetName); } catch (UnsupportedEncodingException e) {
	    }
	    return src.getBytes();
	}

	public static int stringToInt(String src)
	{
		try
	    {
	      return Integer.parseInt(src); } catch (Exception e) {
	    }
	    return 0;
	}

	public static String intToString(int value)
	{
		return String.valueOf(value);
	}

	public static byte[] concat(byte bytes1[], byte bytes2[])
	{
		int len1 = bytes1.length;
		int len2 = bytes2.length;
		byte result[] = new byte[len1 + len2];
		System.arraycopy(bytes1, 0, result, 0, len1);
		System.arraycopy(bytes2, 0, result, len1, len2);
		return result;
	}

	public static byte[] concat(byte bytes1[], int beginIndex1, int length1, byte bytes2[], int beginIndex2, int length2)
	{
		byte result[] = new byte[length1 + length2];
		System.arraycopy(bytes1, beginIndex1, result, 0, length1);
		System.arraycopy(bytes2, beginIndex2, result, length1, length2);
		return result;
	}

	public static byte[] fill(String src, int length, byte b, boolean flag, String charsetName)
	{
		if (isEmpty(src))
			return fill(b, length);
		byte bSrc[] = stringToByte(src, charsetName);
		int len = bSrc.length;
		if (len >= length)
			return bSrc;
		byte res[] = (byte[])null;
		res = fill(b, length);
		if (flag)
			System.arraycopy(bSrc, 0, res, length - len, len);
		else
			System.arraycopy(bSrc, 0, res, 0, len);
		return res;
	}

	public static byte[] fillLeft(String src, int length, byte b, String charsetName)
	{
		return fill(src, length, b, true, charsetName);
	}

	public static byte[] fillLeftZero(String src, int length, String charsetName)
	{
		return fill(src, length, (byte)48, true, charsetName);
	}

	public static String fill(int value, char c, int length)
	{
		String src = intToString(value);
		int len = src.length();
		StringBuffer sBuffer = new StringBuffer();
		for (int i = 0; i < length - len; i++)
			sBuffer.append(c);

		sBuffer.append(src);
		return sBuffer.toString();
	}

	public static String fillLeftZero(int value, int length)
	{
		return fill(value, '0', length);
	}

	public static byte[] fillRight(String src, int length, byte b, String charsetName)
	{
		return fill(src, length, b, false, charsetName);
	}

	public static byte[] fillRightBlank(String src, int length, String charsetName)
	{
		return fill(src, length, (byte)32, false, charsetName);
	}

	public static byte[] fill(byte b, int length)
	{
		byte bytes[] = new byte[length];
		Arrays.fill(bytes, b);
		return bytes;
	}

	public static boolean isEmpty(String src)
	{
		return src == null || src.length() == 0;
	}

	public static String trim(String src)
	{
		return src != null ? src.trim() : "";
	}

	public static String unPadLeft(String s, char c)
	{
		if (isEmpty(s))
			return null;
		int fill = 0;
		int end = s.length();
		if (end == 0)
			return s;
		for (; fill < end && s.charAt(fill) == c; fill++);
		return fill >= end ? s.substring(fill - 1, end) : s.substring(fill, end);
	}

	public static String unPadRight(String s, char c)
	{
		if (isEmpty(s))
			return null;
		int end = s.length();
		if (end == 0)
			return s;
		for (; end > 0 && s.charAt(end - 1) == c; end--);
		return end <= 0 ? s.substring(0, 1) : s.substring(0, end);
	}

	public static String zeroUnPad(String s)
	{
		return unPadLeft(s, '0');
	}

	public static String blankUnPad(String s)
	{
		return unPadRight(s, ' ');
	}

	public static String fillLeftString(String val, int length, String src)
	{
		if (isEmpty(val))
			return null;
		StringBuffer newval = new StringBuffer();
		if (val.length() < length)
		{
			int max = length - val.length();
			for (int i = 0; i < max; i++)
				newval.append(src);

			newval.append(val);
		} else
		{
			newval.append(val);
		}
		return newval.toString();
	}

	public static void main(String args[])
	{
		System.out.println(fillLeftString("256", 5, "0"));
	}
}
